<?php
namespace app\index\controller;
use app\index\controller\Basic;
use think\Db;
class Search extends Basic{
	public function _initialize(){parent::_initialize();}
	public function index(){
		if (request()->isPost()){
			$cid = intval($_POST['cid']);
			if($cid==0 || $cid>6) $this->redirect('/');
			$model = Db::name('cal')->where('id',$cid)->find();
			if($model){
				$key = htmlspecialchars(strip_tags(trim($_POST['key'])));
				$ret = get_search($model['table'],$this->lid,$key,9,1);
				if($ret['datalist']){
					foreach($ret['datalist'] as $v){
						$v['url']   =  '/content_'.$v['navid'].'_'.$v['id'].'.html';
						$datalist[] = $v;
					}
					$pagelist = $ret['pagelist'];
					$this->assign('pagelist',$pagelist);
					$this->assign('datalist',$datalist);
				}
			}
			return $this->fetch('search_'.$model['table']);
		}else{
			$this->redirect('/');
		}
	}
}